package com.atguigu.controller;

import com.atguigu.dto.h5.ProductSkuDto;
import com.atguigu.entity.product.ProductSku;
import com.atguigu.service.ProductService;
import com.atguigu.vo.common.Result;
import com.atguigu.vo.common.ResultCodeEnum;
import com.atguigu.vo.h5.ProductItemVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @Operation(summary = "商品详情")
    @GetMapping("item/{skuId}")
    public Result detail(@PathVariable Long skuId) {
        ProductItemVo productItemVo = productService.detail(skuId);
        return Result.build(productItemVo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "分页查询")
    @GetMapping(value = "/{page}/{limit}")
    public Result page(@PathVariable Integer page, @PathVariable Integer limit, ProductSkuDto productSkuDto) {
        PageInfo<ProductItemVo> pageInfo = productService.page(page, limit, productSkuDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "")
    @GetMapping("/getBySkuId/{skuId}")
    public Result getBySkuId(@PathVariable Long skuId) {
        ProductSku productSku = productService.getBySkuId(skuId);
        return Result.build(productSku, ResultCodeEnum.SUCCESS);
    }
}
